package com.example.car.vo;

import java.util.HashMap;
import java.util.Map;

public class CommonResult {

    private int code;

    private String message;

    private Map<String, Object> data = new HashMap<String, Object>();

    // 把构造方法私有
    private CommonResult() {}

    // 成功
    public static CommonResult success() {
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(200);
        commonResult.setMessage("成功");
        return commonResult;
    }

    public static CommonResult success(int code, String message) {
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(code);
        commonResult.setMessage(message);
        return commonResult;
    }

    // 失败
    public static CommonResult error() {
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(600);
        commonResult.setMessage("失败");
        return commonResult;
    }

    // 失败
    public static CommonResult error(String message) {
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(600);
        commonResult.setMessage(message);
        return commonResult;
    }

    public static CommonResult error(int code, String message) {
        CommonResult commonResult = new CommonResult();
        commonResult.setCode(code);
        commonResult.setMessage(message);
        return commonResult;
    }

    public CommonResult data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public CommonResult data(Map<String, Object> map){
        this.setData(map);
        return this;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }
}
